//	Author: EJS
//	This file describes a simple demo game to run on the RPDroid engine

//Skilgreinum leikinn (Adventure)

var game = new Adventure()
game.adventureName = "Machinarium"
game.screenList = []
game.worldmap = "map_bg.jpg"
game.backgroundMusic = "backgroundtheme.mp3"
game.items = []
game.journalLogs = []

//journalLogs

var logBeginning = new JournalLog()
logBeginning.logId = 0
logBeginning.logDescription = "You have seen a large machine-city. Find out what's inside!"
logBeginning.completed = false
logBeginning.playerHasJournalLog = true
game.journalLogs[0] = logBeginning

var logExploreCity = new JournalLog()
logExploreCity.logId = 1
logExploreCity.logDescription = "You have entered the machine-city. Explore!"
logExploreCity.completed = false
logExploreCity.playerHasJournalLog = false
game.journalLogs[1] = logExploreCity

var logFixComputer = new JournalLog();
logFixComputer.logId = 2
logFixComputer.logDescription = "You found an unresponsive computer. Try to fix it!"
logFixComputer.completed = false
logFixComputer.playerHasJournalLog = false
game.journalLogs[2] = logFixComputer

//items

var hammer = new Item()
hammer.itemId = 0
hammer.itemDescription = "The hammer can be used as a blunt weapon... or to nail nails."
hammer.itemImage = "items/hammer.jpg"
hammer.playerHasItem = false
game.items[0] = hammer

//screenList:

var outside = new Screen()
outside.screenId = 0
outside.screenImage = "outside.jpg"
outside.screenDescription = "The Wastes"
outside.interQuestion = "For days, you have traveled through the windswept crags of Markonaria. At long last, you reach a settlement of some sort, although it is unlike any you have ever seen before."
outside.textAnswers = []
outside.imageAnswers = []
outside.imageAnswers.push(["325, 241, 342, 242, 343, 277, 325, 271, 325, 241",1])
outside.sound = "WindBlowing.mp3"
outside.backgroundMusic = ""
outside.coordinates = [423,295]
outside.screenfunc = noFunction
game.screenList[0] = outside

var plaza = new Screen()
plaza.screenId = 1
plaza.screenImage = "plaza.jpg"
plaza.screenDescription = "The plaza"
plaza.interQuestion = "As you enter the town's central plaza, its unusual nature becomes even more obvious. The town's population seems to consist entirely of robots, who stare at you with mild curiosity. Where will you go from here?"
plaza.imageAnswers = []
plaza.textAnswers = []
plaza.imageAnswers.push(["310, 415, 310, 350, 425, 350, 425, 415, 310, 415",2])
plaza.imageAnswers.push(["60, 420, 84, 427, 73, 478, 1, 478, 60, 420",4])
plaza.imageAnswers.push(["465, 319, 633, 339, 635, 250, 474, 222, 465, 319",7])
plaza.coordinates = [312,174]
plaza.screenfunc = enterCity
game.screenList[1] = plaza

var well = new Screen()
well.screenId = 2
well.screenImage = "well.jpg"
well.screenDescription = "The well"
well.interQuestion = "You went down a well. There is a surprising amount of machinery down here. A nearby crate piques your interest."
well.imageAnswers = []
well.textAnswers = []
well.imageAnswers.push(["300, 65, 370, 65, 370, 45, 300, 45, 300, 65",3])
if(hammer.playerHasItem==false) {
	well.imageAnswers.push(["520, 343, 563, 343, 563, 300, 516, 296, 520, 343",10]) // fara á well2 með því að smella á crate
}
well.coordinates = [353,478]
well.screenfunc = noFunction
game.screenList[2] = well

var plaza2 = new Screen()
plaza2.screenId = 3
plaza2.screenImage = "plaza.jpg"
plaza2.screenDescription = "The plaza"
plaza2.interQuestion = "You are back at the plaza. Where will you go?"
plaza2.imageAnswers = []
plaza2.textAnswers = []
plaza2.imageAnswers.push(["310, 415, 310, 350, 425, 350, 425, 415, 310, 415",2])
plaza2.imageAnswers.push(["60, 420, 84, 427, 73, 478, 1, 478, 60, 420",4])
plaza2.imageAnswers.push(["465, 319, 633, 339, 635, 250, 474, 222, 465, 319",7])
plaza2.coordinates = [214,498]
plaza2.screenfunc = noFunction
game.screenList[3] = plaza2

var smallplaza = new Screen()
smallplaza.screenId = 4
smallplaza.screenImage = "small_plaza.jpg"
smallplaza.screenDescription = "The back alley"
smallplaza.interQuestion = "You enter a seedy back alley. In one corner, three robotic musicians are playing primitive instruments."
smallplaza.imageAnswers = []
smallplaza.textAnswers = []
smallplaza.imageAnswers.push(["108, 381, 301, 357, 210, 230, 106, 278, 108, 381",5])
smallplaza.imageAnswers.push(["466, 319, 367, 320, 355, 213, 467, 108, 466, 319",3])
smallplaza.imageAnswers.push(["543, 366, 515, 349, 523, 277, 544, 275, 543, 366",6])
smallplaza.coordinates = [152,224]
smallplaza.screenfunc = noFunction
game.screenList[4] = smallplaza

var theend = new Screen()
theend.screenId = 5
theend.screenImage = "theend.jpeg"
theend.screenDescription = "The end"
theend.interQuestion = "The musicians turn out to be killbots in hiding. Once you approach them, they turn on you, and kill you in order to preserve their cover."
theend.imageAnswers = []
theend.textAnswers = []
theend.imageAnswers.push(["1, 479, 639, 479, 639, 1, 1, 1, 1, 479",99])
theend.coordinates = false
theend.screenfunc = noFunction
game.screenList[5] = theend

var youwin = new Screen()
youwin.screenId = 6
youwin.screenImage = "youwin.jpeg"
youwin.screenDescription = "You win"
youwin.interQuestion = "Entering an abandoned automobile shop, you find enough supplies to last you a lifetime, and you live happily ever after."
youwin.imageAnswers = []
youwin.textAnswers = []
youwin.imageAnswers.push(["1, 479, 639, 479, 639, 1, 1, 1, 1, 479",99])
youwin.coordinates = false
youwin.screenfunc = winFunc
game.screenList[6] = youwin

var bridge = new Screen()
bridge.screenId = 7
bridge.screenImage = "bridge.jpg"
bridge.screenDescription = "The bridge"
bridge.interQuestion = "As you enter the brighter parts of the town, you come upon a bridge."
bridge.imageAnswers = []
bridge.textAnswers = []
bridge.imageAnswers.push(["559, 403, 633, 377, 632, 466, 562, 426, 559, 403",3])
bridge.imageAnswers.push(["76, 352, 66, 251, 104, 233, 113, 329, 76, 352",8])
bridge.coordinates = [431,512]
bridge.screenfunc = initGameroom
game.screenList[7] = bridge

var gameroom = new Screen()
gameroom.screenId = 8
gameroom.screenImage = "gameroom.png"
gameroom.screenDescription = "The game room"
gameroom.interQuestion = "You enter a chamber in which stands an enormous machine, whose purpose is unclear."
gameroom.imageAnswers = []
gameroom.textAnswers = []
gameroom.imageAnswers[0] = (["588, 415, 587, 298, 625, 308, 624, 429, 588, 415",7])
gameroom.coordinates = [152,310]
gameroom.screenfunc = noFunction
game.screenList[8] = gameroom 

var gameroom2 = new Screen()
gameroom2.screenId = 9
gameroom2.screenImage = "gameroom.png"
gameroom2.screenDescription = "The game room"
gameroom2.interQuestion = "The machine appears to be unresponsive."
gameroom2.imageAnswers = []
gameroom2.textAnswers = []
gameroom2.imageAnswers.push(["588, 415, 587, 298, 625, 308, 624, 429, 588, 415",7])
gameroom2.coordinates = false
gameroom2.screenfunc = findWayToFixComputer
game.screenList[9] = gameroom2

var well2 = new Screen()
well2.screenId = 10
well2.screenImage = "well.jpg"
well2.screenDescription = "The well"
well2.interQuestion = "You look in the crate and find a hammer. You have put it into your inventory."
well2.imageAnswers = []
well2.textAnswers = []
well2.imageAnswers.push(["300, 65, 370, 65, 370, 45, 300, 45, 300, 65",3]) // return up, now with hammer
well2.coordinates = [353,478]
well2.screenfunc = getHammer
game.screenList[10] = well2

var gameroom3 = new Screen()
gameroom3.screenId = 11
gameroom3.screenImage = "brokengame.gif"
gameroom3.screenDescription = "The game room"
gameroom3.interQuestion = "You attempt to fix the computer with your hammer... and completely wreck it. You don't fix computers with a hammer! You should learn from this experience!"
gameroom3.imageAnswers = []
gameroom3.textAnswers = []
gameroom3.imageAnswers.push(["588, 415, 587, 298, 625, 308, 624, 429, 588, 415",7])
gameroom3.coordinates = false
gameroom3.screenfunc = computerIsWrecked;
game.screenList[11] = gameroom3

var gameroom4 = new Screen()
gameroom4.screenId = 12
gameroom4.screenImage = "brokengame.gif"
gameroom4.screenDescription = "The game room"
gameroom4.interQuestion = "The machine has been completely wrecked... for shame!"
gameroom4.imageAnswers = []
gameroom4.textAnswers = []
gameroom4.imageAnswers.push(["588, 415, 587, 298, 625, 308, 624, 429, 588, 415",7])
gameroom4.coordinates = false
gameroom4.screenfunc = noFunction
game.screenList[12] = gameroom4

var waitingscreen = new Screen()
waitingscreen.screenId = 99
waitingscreen.screenImage = "outside.jpg"
waitingscreen.screenDescription = "Please wait"
waitingscreen.interQuestion = "Please wait"
waitingscreen.imageAnswers = []
waitingscreen.textAnswers = []
waitingscreen.coordinates = false
waitingscreen.screenfunc = resetGame
game.screenList[99] = waitingscreen

//functions

function getHammer() {
	game.items[0].playerHasItem = true; //set hammer item to inventory
	well.imageAnswers.pop() //svo hamarinn er farinn og leikmaður kemst ekki aftur á skjá 10
}

function completeLogBeginning() {
	game.journalLogs[0].completed = true; //setja sem completed
}

function initGameroom() {
	if(game.items[0].playerHasItem==false)
		gameroom.imageAnswers[1] = (["122, 358, 83, 67, 255, 40, 235, 341, 122, 358",9])
	else
		gameroom.imageAnswers[1] = (["122, 358, 83, 67, 255, 40, 235, 341, 122, 358",11])
}

function findWayToFixComputer() {
	game.journalLogs[2].playerHasJournalLog = true
}

function winFunc() {
	game.journalLogs[1].completed = true
}

function computerIsWrecked() {
	game.journalLogs[2].playerHasJournalLog = true
	game.journalLogs[2].completed = true
	bridge.screenfunc = false
	gameroom.imageAnswers[1] = (["122, 358, 83, 67, 255, 40, 235, 341, 122, 358",12])
}

function resetGame() {
	history.go(0);
}

function noFunction() {}

function enterCity() {
	game.journalLogs[0].completed = true
	game.journalLogs[1].playerHasJournalLog = true
}